﻿using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UDS.Web.UI.Controls
{
    /// <summary>
    /// Specify the direction that an arrow indicates.
    /// </summary>
    public enum ArrowDirection
    {
        Left,
        Right,
        Top,
        Bottom,
        TopLeft,
        TopRight,
        BottomRight,
        BottomLeft,
    }

    public class Arrow : WebControl
    {
        /// <summary>
        /// Get or set the direction that the arrow indicates.
        /// </summary>
        [PersistenceMode(PersistenceMode.Attribute)]
        [DefaultValue(ArrowDirection.Right)]
        public ArrowDirection Direction
        {
            get;
            set;
        }

        public Arrow()
        {
            Direction = ArrowDirection.Right;
        }

        public static string GetHtmlCode(ArrowDirection d)
        {
            switch (d)
            {
                case ArrowDirection.Left: return "<span style=\"font-family:Wingdings;\">&#239;</span>";
                case ArrowDirection.Right: return "<span style=\"font-family:Wingdings;\">&#240;</span>";
                case ArrowDirection.Top: return "<span style=\"font-family:Wingdings;\">&#241;</span>";
                case ArrowDirection.Bottom: return "<span style=\"font-family:Wingdings;\">&#242;</span>";
                case ArrowDirection.TopLeft: return "<span style=\"font-family:Wingdings;\">&#245;</span>";
                case ArrowDirection.TopRight: return "<span style=\"font-family:Wingdings;\">&#246;</span>";
                case ArrowDirection.BottomLeft: return "<span style=\"font-family:Wingdings;\">&#247;</span>";
                case ArrowDirection.BottomRight: return "<span style=\"font-family:Wingdings;\">&#248;</span>";
            }
            throw new ArgumentOutOfRangeException("d", string.Format("Undefined arrow direction: {0}.", d));
        }

        /// <summary>
        /// Render the content to the given writer.
        /// </summary>
        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write(GetHtmlCode(Direction));
        }
    }
}
